<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2010 osCommerce

  Released under the GNU General Public License
*/

  require('includes/application_top.php');

  if (!tep_session_is_registered('customer_id')) {
    $navigation->set_snapshot();
    tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
  }

  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_ADDRESS_BOOK);

  $breadcrumb->add(NAVBAR_TITLE_1, tep_href_link(FILENAME_ACCOUNT, '', 'SSL'));
  $breadcrumb->add(NAVBAR_TITLE_2, tep_href_link(FILENAME_ADDRESS_BOOK, '', 'SSL'));

  require(DIR_WS_INCLUDES . 'template_top.php');
?>
<!--middle area start-->

<div class="middle-area">
  <div class="innermidbox fl">
    <div class="innermidbox-top"></div>
    <div class="innermidbox-mid">
      <div class="pdt5 pdl20 pdr20 pdb5 minheight527px">
        <div class="breadcrumbs"><a href="index.php">Home</a> > <span><?php echo HEADING_TITLE; ?></span></div>
        <div class="spacer10"></div>
        <div class="">
          <h1 class="pagetitle fl"><?php echo HEADING_TITLE; ?></h1>
          <a href="<?=tep_href_link(FILENAME_ACCOUNT, '', 'SSL')?>" class="backbtn fr"></a>
          <div class="clear"></div>
          <div class="hline"></div>
          <div class="spacer3"></div>
          <!--left panel start-->
          <?php include('includes/template_left.php'); ?>
          <!--left panel end-->
          <!--right panel start-->
          <div class="rightpanel mgl15 fl">
            <?php
  if ($messageStack->size('addressbook') > 0) {
    echo $messageStack->output('addressbook');
  }
?>
            <div class="cms">
              <h3><?php echo PRIMARY_ADDRESS_TITLE; ?></h3>
              <div class="spacer10"></div>
              <div class="fl w350"><?php echo PRIMARY_ADDRESS_DESCRIPTION; ?></div>
              <div class="addressinfobox pdl10 pdt10 pdr10 pdb10 fr"> <strong>
                <?=PRIMARY_ADDRESS_TITLE?>
                </strong> <br />
                <?php echo tep_address_label($customer_id, $customer_default_address_id, true, ' ', '<br />'); ?> </div>
              <div class="spacer20"></div>
              <h3><?php echo ADDRESS_BOOK_TITLE; ?></h3>
              <div class="spacer10"></div>
              <?php
		$addresses_query = tep_db_query("select address_book_id, entry_firstname as firstname, entry_lastname as lastname, entry_company as company, entry_street_address as street_address, entry_suburb as suburb, entry_city as city, entry_postcode as postcode, entry_state as state, entry_zone_id as zone_id, entry_country_id as country_id from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$customer_id . "' order by firstname, lastname");
		$i=0;
  		while($addresses = tep_db_fetch_array($addresses_query)) 
		{
    		$format_id = tep_get_address_format_id($addresses['country_id']);
			$i++;
?>
              <?php
					if($i%2==0){
                ?>
              <div class="fr">
                <?php
					}else{
                ?>
                <div class="clear"></div>
                <div class="fl">
                  <?php
					}
                ?>
                  <div class="addressinfobox pdl10 pdt10 pdr10 pdb10 fl"> <strong><?php echo tep_output_string_protected($addresses['firstname'].' '.$addresses['lastname']); ?></strong>
                    <?php if ($addresses['address_book_id'] == $customer_default_address_id) echo '<small><i>' . PRIMARY_ADDRESS . '</i></small>'; ?>
                    <br />
                    <?php echo tep_address_format($format_id, $addresses, true, ' ', '<br />'); ?> </div>
                  <div class="spacer15"></div>
                  <a href="<?=tep_href_link(FILENAME_ADDRESS_BOOK_PROCESS,'edit='.$addresses['address_book_id'],'SSL')?>" class="edit-btn fl mgr10"></a> <a href="<?=tep_href_link(FILENAME_ADDRESS_BOOK_PROCESS, 'delete=' . $addresses['address_book_id'], 'SSL')?>" class="delete-btn fl"></a> </div>
                <?php
  			}
		?>
                <div class="spacer20"></div>
                <div class="fl"><?php echo sprintf(TEXT_MAXIMUM_ENTRIES, MAX_ADDRESS_BOOK_ENTRIES); ?></div>
                <?php
  			if(tep_count_customer_address_book_entries() < MAX_ADDRESS_BOOK_ENTRIES) 
			{
		?>
                <a href="<?=tep_href_link(FILENAME_ADDRESS_BOOK_PROCESS, '', 'SSL')?>" class="addaddress-btn fr"></a>
                <?php
  			}
		?>
              </div>
              <div class="spacer10"></div>
              <!--listing end-->
            </div>
            <!--right panel end-->
            <div class="spacer10"></div>
          </div>
        </div>
      </div>
      <div class="innermidbox-bottom"></div>
    </div>
  </div>
  <!--middle area end-->
  <div class="spacer25"></div>
</div>
<?php
  require(DIR_WS_INCLUDES . 'template_bottom.php');
  require(DIR_WS_INCLUDES . 'application_bottom.php');
?>
